package com.ke.rule.base;

import com.google.common.base.Splitter;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 功能部件的应用对象
 * 
 * @author guyu
 */
public final class FuncUnitApplyTo implements IFuncUnit.ApplyTo {
  private ApplyToType type;
  private String which;
  private Map<String, String> map;  // 将which分割为map

  public FuncUnitApplyTo() {
    super();
  }
  
  public FuncUnitApplyTo(ApplyToType type, String which) {
    super();
    setType(type);
    setWhich(which);
  }

  @Override
  public ApplyToType getType() {
    return type;
  }

  @Override
  public String getWhich() {
    return which;
  }

  public void setType(ApplyToType type) {
    this.type = type;
  }

  public void setWhich(String which) {
    this.which = which;
    if (StringUtils.isNotBlank(which) && which.contains("=")) {
      this.map = Splitter.on(",").withKeyValueSeparator("=").split(which);
    }
  }
  
  @Override
  public Map<String, String> getWhichInKv() {
    return map;
  }

  @Override
  public String toString() {
    return "FuncUnitApplyTo [type=" + type + ", which=" + which + "]";
  }
  
}
